<?php
/**
 * 新闻控制器包含（新闻，视频，小视频，娱乐，交友）
 */
namespace app\index\controller;
use app\common\exception\System as SystemException;
use Exception;
class Upload extends Common
{
  /**
   * 不需要登录
   * @var array
   */
  protected $noNeedLogin = ['*'];
  /**
   * 新闻首页
   * @return [type] [description]
   */
	public function index(){
		$file = request()->file('file');
        $info = $file->validate(['size'=>2097152000,'ext'=>'jpg,png,gif,mp3'])->move( '../public/uploads/');
        if($info){
            $user_images='../public/uploads/'.$info->getSaveName();
            $user_images=str_replace('\\','/',$user_images);
            $img = \think\Image::open($user_images);
            $img->thumb(500,500)->save($user_images);
            $user_images=str_replace('../public/','http://yijiazhihui.40b876.cn/',$user_images);
            $jsonRes=['code'=>1,'data'=>$user_images,'msg'=>'上传成功'];  
        }else{
            $res=$file->getError();
            $jsonRes=['code'=>0,'msg'=>$res];  
        }
        return $this->successReturn($user_images,SystemException::E_SUCCESS,'ok');
	}
  public function upload(){
    $file = request()->file('file');
        $info = $file->validate(['size'=>209715200000,'ext'=>'mp4'])->move( '../public/uploads/');
        if($info){
            $user_images='http://yijiazhihui.40b876.cn/uploads/'.$info->getSaveName();
            $user_images=str_replace('\\','/',$user_images);
            // $user_images=str_replace('../public/','http://yijiazhihui.40b876.cn/',$user_images);
            $jsonRes=['code'=>1,'data'=>$user_images,'msg'=>'上传成功'];  
        }else{
            $res=$file->getError();
            $jsonRes=['code'=>0,'msg'=>$res];  
        }
        return $this->successReturn($user_images,SystemException::E_SUCCESS,'ok');
  }
}